import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    state.routes = [
      ...constantRoutes,
      ...data
    ]
  }
}

const actions = {
  filterRoutes(store, menus) {
    const newAsyncRoutes = asyncRoutes.filter(item => menus.includes(item.name))
    store.commit('setRoutes', newAsyncRoutes)
    return newAsyncRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
